#ifndef __DRIVERS_INSDRV_I2C_H__
#define __DRIVERS_INSDRV_I2C_H__


#include "BAT32G157.h"


#define __ATTRIB_WEAK__ __attribute__((weak))
#define __ATTRIB_ALIAS__(symbol)	 __attribute__((alias(#symbol)))
#define __ATTRIB_PACK__ __attribute__((packed))
#define __ATTRIB_ALIGNED(x)__ __attribute__((aligned(x)))

#define INSERR_NG  0
#define INSERR_OK  1

#define PLATFORM_CHIP PLATFORM_BAT32G157

typedef enum _InsDrv_I2c_Id_e
{
    INSDRV_I2C0 = 0,
    INSDRV_I2C1,

    INSDRV_I2C_NUM,
}InsDrv_I2c_Id_e;

typedef enum _InsDrv_I2c_Speed_e
{
    INSDRV_I2C_SPEED_STANDARD = 0,
    INSDRV_I2C_SPEED_FAST,
    INSDRV_I2C_SPEED_PLUS,

}InsDrv_I2c_Speed_e;

typedef struct _InsDrv_I2c_Ctrl_s
{
    InsDrv_I2c_Id_e id;
    InsDrv_I2c_Speed_e speed;
}InsDrv_I2c_Ctrl_t;

#if (PLATFORM_CHIP == PLATFORM_BAT32G137)
    //#include <platform/BAT32G137/drivers/gpio_BAT32G137.h>
    //#include "gpio_BAT32G137.h"
#elif (PLATFORM_CHIP == PLATFORM_BAT32G135S)
    //#include <platform/BAT32G135S/drivers/gpio_BAT32G135S.h>
    //#include "gpio_BAT32G135S.h"
#elif (PLATFORM_CHIP == PLATFORM_BAT32G157)
    //#include <platform/BAT32G157/drivers/gpio_BAT32G157.h>
    #include "gpio_BAT32G157.h"
#else
#endif
void delay_1us(uint32_t us);
int32_t InsDrv_I2c_Init(void);
int32_t InsDrv_I2c_MasterWrite(InsDrv_I2c_Ctrl_t ctrl, uint8_t addr, uint8_t *tx_buf, uint32_t tx_len, uint32_t timeout);
int32_t InsDrv_I2c_MasterRead(InsDrv_I2c_Ctrl_t ctrl, uint8_t addr, uint8_t *rx_buf, uint32_t rx_len, uint32_t timeout);
int32_t InsDrv_I2c_SetSpeed(InsDrv_I2c_Ctrl_t ctrl, InsDrv_I2c_Speed_e speedmode);

int _i2c1_rcv(uint8_t slave_addr, uint8_t reg_addr, uint8_t *dat, uint8_t len);
int _i2c1_send(uint8_t slave_addr, uint8_t reg_addr, uint8_t *dat, uint8_t len);
#endif

